/*
 * @Author: chen haoxuan
 * @Date: 2021-06-28 21:15:12
 * @LastEditTime: 2021-06-28 21:24:47
 */
#include<iostream>
using namespace std;
class base
{
  public:
    int n;
    base(int x) {n=x;}
    virtual void set(int m)
    {
      n=m;
      cout<<n<<" ";
    }
};
class deriveA:public base
{
  public:
    deriveA(int x):base(x) {}
    void set(int m)
    {
      n+=m;
      cout<<n<<" ";
    }
};
class deriveB:public base
{
  public:
    deriveB(int x):base(x){}
    void set(int m)
    {
      n+=m;
      cout<<n<<" ";
    }
};
int main()
{
  deriveA d1(1);
  deriveB d2(3);
  base *pbase;
  pbase=&d1;
  pbase->set(1);      // 2
  pbase=&d2;
  pbase->set(2);      // 5
  return 0;
}